package entityrelationship.diagram.edit.parts;

import javax.management.Notification;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Connection;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITreeBranchEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
import org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
import org.eclipse.gmf.runtime.notation.View;

import entityrelationship.Connection_Entity_Relationship;
import entityrelationship.diagram.edit.policies.Connection_Entity_RelationshipItemSemanticEditPolicy;
import entityrelationship.diagram.edit.parts.custom.AutomaticCardinalityRelationship;

/**
 * @generated
 */
public class Connection_Entity_RelationshipEditPart extends
		ConnectionNodeEditPart implements ITreeBranchEditPart {

	/**
	 * @generated
	 */
	public static final int VISUAL_ID = 4001;

	/**
	 * @generated
	 */
	public Connection_Entity_RelationshipEditPart(View view) {
		super(view);
	}

	/**
	 * @generated
	 */
	protected void createDefaultEditPolicies() {
		super.createDefaultEditPolicies();
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
				new Connection_Entity_RelationshipItemSemanticEditPolicy());
	}

	/**
	 * @generated
	 */
	protected boolean addFixedChild(EditPart childEditPart) {
		if (childEditPart instanceof Connection_Entity_RelationshipRoleEditPart) {
			((Connection_Entity_RelationshipRoleEditPart) childEditPart)
					.setLabel(getPrimaryShape()
							.getFigureConnection_Entity_RelationshipRoleFigure());
			return true;
		}
		if (childEditPart instanceof Connection_Entity_RelationshipMinimum_cardinalityMaxiEditPart) {
			((Connection_Entity_RelationshipMinimum_cardinalityMaxiEditPart) childEditPart)
					.setLabel(getPrimaryShape()
							.getFigureConnection_Entity_RelationshipCardinalityFigure());
			return true;
		}
		return false;
	}

	/**
	 * @generated
	 */
	protected void addChildVisual(EditPart childEditPart, int index) {
		if (addFixedChild(childEditPart)) {
			return;
		}
		super.addChildVisual(childEditPart, index);
	}

	/**
	 * @generated
	 */
	protected boolean removeFixedChild(EditPart childEditPart) {
		if (childEditPart instanceof Connection_Entity_RelationshipRoleEditPart) {
			return true;
		}
		if (childEditPart instanceof Connection_Entity_RelationshipMinimum_cardinalityMaxiEditPart) {
			return true;
		}
		return false;
	}

	/**
	 * @generated
	 */
	protected void removeChildVisual(EditPart childEditPart) {
		if (removeFixedChild(childEditPart)) {
			return;
		}
		super.removeChildVisual(childEditPart);
	}

	/**
	 * Creates figure for this edit part.
	 * 
	 * Body of this method does not depend on settings in generation model
	 * so you may safely remove <i>generated</i> tag and modify it.
	 * 
	 * @generated
	 */

	protected Connection createConnectionFigure() {
		return new Connection_Entity_RelationshipFigure();
	}

	/**
	 * @generated
	 */
	public Connection_Entity_RelationshipFigure getPrimaryShape() {
		return (Connection_Entity_RelationshipFigure) getFigure();
	}

	/**
	 * @generated NOT
	 */
	protected void handleNotificationEvent(
			org.eclipse.emf.common.notify.Notification notification) {
		super.handleNotificationEvent(notification);
		if (notification.getNotifier() instanceof Connection_Entity_Relationship) {
			AutomaticCardinalityRelationship
					.AutomaticCardinalityRelationship((Connection_Entity_Relationship) notification
							.getNotifier());
		}
	}

	/**
	 * @generated
	 */
	public class Connection_Entity_RelationshipFigure extends
			PolylineConnectionEx {

		/**
		 * @generated
		 */
		private WrappingLabel fFigureConnection_Entity_RelationshipRoleFigure;
		/**
		 * @generated
		 */
		private WrappingLabel fFigureConnection_Entity_RelationshipCardinalityFigure;

		/**
		 * @generated
		 */
		public Connection_Entity_RelationshipFigure() {
			this.setForegroundColor(ColorConstants.black);

			createContents();
		}

		/**
		 * @generated
		 */
		private void createContents() {

			fFigureConnection_Entity_RelationshipRoleFigure = new WrappingLabel();

			fFigureConnection_Entity_RelationshipRoleFigure.setText("Role");

			this.add(fFigureConnection_Entity_RelationshipRoleFigure);

			fFigureConnection_Entity_RelationshipCardinalityFigure = new WrappingLabel();

			fFigureConnection_Entity_RelationshipCardinalityFigure
					.setText("( , )");

			this.add(fFigureConnection_Entity_RelationshipCardinalityFigure);

		}

		/**
		 * @generated
		 */
		public WrappingLabel getFigureConnection_Entity_RelationshipRoleFigure() {
			return fFigureConnection_Entity_RelationshipRoleFigure;
		}

		/**
		 * @generated
		 */
		public WrappingLabel getFigureConnection_Entity_RelationshipCardinalityFigure() {
			return fFigureConnection_Entity_RelationshipCardinalityFigure;
		}

	}

}
